//
// Created by 高森森 on 2022/2/17.
//

#ifndef LEETCODE_SOLUTION55_H
#define LEETCODE_SOLUTION55_H
#include<iostream>
#include<vector>
#include <unordered_map>
#include <queue>
using namespace std;

class Solution55 {
public:
    unordered_map<string,priority_queue<string,vector<string>,greater<string>>>graph;
    vector<string>res;//用栈保存
    vector<string> findItinerary(vector<vector<string>>& tickets) {
        for(auto &t:tickets){
            graph[t[0]].emplace(t[1]);
        }
        dfs("JFK");
        return res;
    }
    void dfs(const string & c){
        while(graph.count(c)&&graph[c].size()>0){
            string tmp=graph[c].top();
            graph[c].pop();
            dfs(tmp);
        }
        res.insert(res.begin(),c);
    }
};


#endif //LEETCODE_SOLUTION55_H
